package com.baiyang.sharding.control;

import com.baiyang.sharding.dao.UserDao;
import com.baiyang.sharding.entity.User;
import com.baiyang.sharding.page.PageEntity;
import com.baiyang.sharding.page.PageHelper;
import com.baiyang.sharding.utils.Letter;
import com.baiyang.sharding.utils.LetterUtils;
import com.baiyang.sharding.utils.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("test")
public class Test {
    @Autowired
    private UserDao userDao;
    private int i = 0;
    @GetMapping
    public void test(){
        User user = new User();
        user.setId(SnowflakeIdWorker.build().nextId());
        user.setName("zhangsan");
        user.setGender(i++);
        userDao.insert(user);
    }


    @GetMapping(value = "page")
    public Letter<List<User>> page(){
        PageHelper.startPage();
        return LetterUtils.success(userDao.list(new User()));
    }


}
